


set matsize 11000
clear all

cd \Data

********************************************************************************
** The following do file produces the estimates displayed in the last two columns
** of Table A15. The results from the last column (second model with averages by
** yearly vintages) are also displayed in Figure 7 -- the SMUD point estimates.


use cons_data.dta, clear
sort premise_id
merge m:1 premise_id using premise_characteristics.dta
keep if _merge == 3
drop _merge

keep if (zoning == "R-1" | zoning == "RD 1" | zoning == "RD 2" | zoning == "RD 3" | zoning == "RD 4" | zoning == "RD 5" | zoning == "RD-1" | zoning == "RD-2" | zoning == "RD-3" | zoning == "RD-4" | zoning == "RD-5" | zoning == "RD1" | zoning == "RD2" | zoning == "RD3" | zoning == "RD4" | zoning == "RD5" | zoning == "RD5PD")
drop if bedrooms_num == 0 | bedrooms_num == .
drop if Resdnc_sqft == 0 | Resdnc_sqft == .
keep if year_built > 1974 & year_built < 1983

** Create premise-level controls for bedrooms (6 bins), square-footage (12 bins),
** and an indicator for multiple stories. Note, premises with missing Assessor
** information will be dropped.

drop if bedrooms_num == 0 | bedrooms_num == .
replace bedrooms_num = 6 if bedrooms_num > 6
drop if Resdnc_sqft == 0 | Resdnc_sqft == .
gen sqft = 0
replace sqft = 1 if Resdnc_sqft < 1000
forvalues i = 2/11 {
	replace sqft = `i' if Resdnc_sqft < 1000 + (`i' - 1) * 150 & Resdnc_sqft >= 1000 + (`i' - 2) * 150
}
replace sqft = 12 if Resdnc_sqft >= 2500
gen multi = 0
replace multi = 1 if stories > 1

** Generate week-of-year variable for two-way clustering

gen week_year = year*100 + week

xtset premise_id

gen period = 1
replace period = 2 if year_built == 1978 | year_built == 1979
replace period = 3 if year_built > 1979

** Note: In models, exlcude controls for 3 bedroom, 1750 sqft, single floor homes built pre-1978 and not on electric heat

char period[omit] 1
char bedrooms_num[omit] 3
char sqft[omit] 6
char multi[omit] 0
char electric_heat[omit] 0


gen CDD=(temp_avg-65)*(temp_avg>65)
gen HDD=(65-temp_avg)*(temp_avg<65)


keep kwh_daily HDD CDD period3 bedrooms_num sqft multi electric_heat premise_id week_year period year_built month_year


** Last two columns of Table A15: Pooled model using CDD with SMUD data

xi: xtivreg2 kwh_daily CDD HDD i.period*CDD i.bedrooms_num*CDD i.sqft*CDD i.multi*CDD i.electric_heat*CDD i.period*HDD i.bedrooms_num*HDD i.sqft*HDD i.multi*HDD i.electric_heat*HDD, fe cluster(premise_id week_year)
	outreg2 CDD HDD i.period3*CDD i.bedrooms_num*CDD i.sqft*CDD i.multi*CDD i.electric_heat*CDD using results/Levinson_rep.doc,  slow(1000) se alpha(.05) symbol(*) replace dec(4) ctitle(years) 

xi: xtivreg2 kwh_daily CDD HDD i.year_built*CDD i.bedrooms_num*CDD i.sqft*CDD i.multi*CDD i.electric_heat*CDD i.year_built*HDD i.bedrooms_num*HDD i.sqft*HDD i.multi*HDD i.electric_heat*HDD, fe cluster(premise_id week_year)
	outreg2 CDD HDD i.year_built*CDD i.bedrooms_num*CDD i.sqft*CDD i.multi*CDD i.electric_heat*CDD using results/Levinson_rep.doc,  slow(1000) se alpha(.05) symbol(*) append dec(4) ctitle(noHDD) 

